<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class log_model extends CI_Model {
	var $table = "jonu_log";

	public function get_all(){
		$this->db->join('jonu_user', 'jonu_user.jonu_user_id = jonu_log.jonu_user_id');
		$this->db->order_by('jonu_log_id', 'desc');
		$query = $this->db->get($this->table);
		$result = $query->result_array();
		return $result;
	}

	public function get_all_paged($num, $offset){
		$this->db->join('jonu_user', 'jonu_user.jonu_user_id = jonu_log.jonu_user_id');
		$this->db->order_by('jonu_log_id', 'desc');
		$query = $this->db->get($this->table, $num, $offset);
		$result = $query->result_array();
		return $result;
	}

	public function get_all_limit(){
		$this->db->join('jonu_user', 'jonu_user.jonu_user_id = jonu_log.jonu_user_id');
		$this->db->order_by('jonu_log_id', 'desc');		
		$query = $this->db->get($this->table, 7);
		$result = $query->result_array();
		return $result;
	}

	public function store($user_id){
		$user_agent = $_SERVER['HTTP_USER_AGENT'];
		$ip = $_SERVER['REMOTE_ADDR'];

		$data = array(
			'jonu_user_id'	=> $user_id,
			'jonu_log_date'	=> date('Y-m-d m:s'),
			'jonu_log_ip'	=> $ip,
			'jonu_log_useragent'	=> $user_agent
			);
		$this->db->insert($this->table, $data);
	}
}

/* End of file log_model.php */
/* Location: ./application/models/log_model.php */